//
// Created by chen on 2021/11/24.
//
#include <stdio.h>
#include "mysql.h"

//#pragma comment(lib, "E:\\wnmp\\mysql\\lib\\libmysql.lib")
#pragma comment(lib, "libmysql")

int main() {
    MYSQL mysql, *sock;
    mysql_init(&mysql);
    const char *Host = "127.0.0.1";
    const char *User = "root";
    const char *Password = "123456";
    const char *DBName = "mysql";
    const unsigned Port = 3306;
    sock = mysql_real_connect(&mysql, Host, User, Password, DBName, Port, NULL, 0);
    if (!sock) {
        printf("Connect Mysql fail\n");
        exit(1);
    }

    MYSQL_RES *result;
    MYSQL_ROW row;
    if (mysql_query(&mysql, "select * from user") != 0) {
        printf("fail to query\n");
    } else {
        result = mysql_store_result(&mysql);
        if (result == NULL) {
            printf("fail to story result\n");
        } else {
            row = mysql_fetch_row(result);
            printf("Host: %s user: %s\n", row[0], row[1]);
        }
    }

    mysql_free_result(result);
    mysql_close(sock);

}